/*
   (C) 2007 - Michael Ocean - Boston University

  This work is a part of the larger snBench project.  Information
  can be found at: http://csr.bu.edu/snbench

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package sxe.sensors;

import java.util.Hashtable;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import snbenchlib.XML;

public class PTZSensorDetector {

	private static final String CONFIG_XML_TAG = "pantiltzoom";
	
	public PTZSensorDetector(){
		super();
		
	}
    static public Hashtable<String, GenericSensor> detect(Element eSensorConfigRoot) {
	    Hashtable<String, GenericSensor> hashTable = new 
		    Hashtable<String, GenericSensor>();
	
		try {
		    if (eSensorConfigRoot==null)
		    	return hashTable;
		    Node nConfig = XML.getChildNodeMatchingTag(eSensorConfigRoot,CONFIG_XML_TAG);
		    if(nConfig == null)
		    	return hashTable;
						
		    Node n;	
		    for( n = nConfig.getFirstChild(); n != null; 
			 n = n.getNextSibling() ) {
				if( n.getNodeType() != Node.ELEMENT_NODE )
				    continue;
		
				Element e = (Element) n;
				if( e.getTagName() != "sensor" ) 
				    continue;
		
				String host = e.getAttribute( "host" );
				if( host == null )
				    continue;
					
				String id = e.getAttribute( "id" );
				String location = e.getAttribute("location");
					    
			    PTZSensor pz = new PTZSensor(host,id,location);
			    hashTable.put( pz.getID(), pz );
			    
				if(!pz.initializeSensor())
					System.err.println("PTZ_ImageSensor " + pz.m_id + " failed to initialize.");
		    }
		} catch( Exception ex ) {
		    ex.printStackTrace() ;
		    return hashTable;
		}
	
		return hashTable;
    }

	
}
